package project.ia04.agents.studio.GUICommunication;

import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import project.ia04.agents.studio.StudioAgent;
import project.ia04.utils.Data;

public class ListenerBehaviour extends CyclicBehaviour {

	@Override
	public void action() {
		final MessageTemplate template = MessageTemplate
				.MatchPerformative(ACLMessage.REQUEST);
		final ACLMessage message = this.myAgent.receive(template);
		if (message != null) {
			if (message.getConversationId().equals(Data.GETCA)) {
				this.myAgent.addBehaviour(new SendCABehaviour(message));
			} else if (message.getConversationId().equals(
					Data.GETSTAFFSLIST)) {
				this.myAgent.addBehaviour(new SendStaffListBehaviour(
						message));
			} else if (message.getConversationId().equals(
					Data.INITGUINEWGAME)) {
				this.myAgent.addBehaviour(new NewGameSequentialBehaviour(
						this.myAgent, message));
			}
			else if(message.getConversationId().equals(Data.GETHISTORICAL)){
				myAgent.addBehaviour(new SendHistoricalBehaviour(message));
			}
			else if(message.getConversationId().equals(Data.TRAIN)){
				myAgent.addBehaviour(new TrainBehaviour(message));
			}
			else if(message.getConversationId().equals(Data.COFFEE)){
				myAgent.addBehaviour(new CoffeeBehaviour(message));
			}
		} else {
			block();
		}
	}
}
